<?php
/**
 * Created by PhpStorm.
 * User: MIS
 * Date: 2018/10/30
 * Time: 9:31
 */
namespace Admin\Controller;
use Think\Controller;
class EditMessageController extends Controller
{
    public function index()
    {

       $id=I("id");
   // var_dump($id);
 //   exit();
        if($id){
            $test = M('test');
            $this->tk_litem=$test->where('`id`='.$id)->find();
//            echo $blank->getLastSql();
//            var_dump($this->tk_litem);
//            var_dump($this->tk_litem["content"]);
//            exit();
            $this->assign('tk_litem',$this->tk_litem);
            $this->assign('test_title',$this->tk_litem["title"]);
            $this->assign('test_name',$this->tk_litem["name"]);
            $this->assign('test_select',$this->tk_litem["select_point"]);
            $this->assign('test_blank',$this->tk_litem["blank_point"]);
            $this->assign('test_judge',$this->tk_litem["judge_point"]);
            $this->assign('test_total',$this->tk_litem["total_point"]);
            $this->assign('test_id',$this->tk_litem["id"]);
            $this->assign('test_litem',"updata");
        }else{
            $this->assign('test_litem',"add");
        }
        $this->display();
        
    }

    public function  add(){
//        var_dump(time());
//        exit();
        $select_point=I("select_point");
        $blank_point=I("blank_point");
        $judge_point=I("judge_point");
        $total_point=$select_point+$blank_point+$judge_point;
        $blank = M('test');
        $data=array(
            "title"=>I("title"),
            "name"=>I("name"),
            "select_point"=>$select_point,
            "blank_point"=>$blank_point,
            "judge_point"=>$judge_point,
            "total_point"=>$total_point,
            "time"=>time(),
        );
        if($blank->add($data)){
            $this->success('试题信息添加成功',U('/Admin/Index/index',array('id'=>$_SESSION["id"])));
        }else{
            $this->error('试题信息添加失败');
        }

    }
    public  function updata(){
        $select_point=I("select_point");
        $blank_point=I("blank_point");
        $judge_point=I("judge_point");
        $total_point=$select_point+$blank_point+$judge_point;
        $id=I('id');
        session("i",$id);
        $blank = M('test');
        $data=array(
            "title"=>I("title"),
            "name"=>I('name'),
            "select_point"=>$select_point,
            "blank_point"=>$blank_point,
            "judge_point"=>$judge_point,
            "total_point"=>$total_point,
            "uptime"=>time(),
        );

        $flag=$blank->where('`id`='.$id)->setField($data);
//        echo $blank->getLastSql();
//                   exit();
        if($flag){
            $this->success('试题信息修改成功',U('/Admin/Index/index',array('id'=>$_SESSION["id"])));
        }else{
            $this->error('试题信息修改失败');
        }
    }

}